﻿using System;
using System.Collections.Generic;
using UtilPublic.ServerLoger;

namespace SvCore.Tcp
{
    public static class SvTcp
    {
        public static Dictionary<uint, Action<MyPackage>> DictAction = new Dictionary<uint, Action<MyPackage>>();
        public static Dictionary<uint, string> DictMethod = new Dictionary<uint, string>();
        public static void AddController<T>(T t)
        {
            if (t == null)
            {
                return;
            }
            Type type = t.GetType();
            var methods = type.GetMethods();
            foreach (var method in methods)
            {
                uint pid = CoreHash.HashMsg(method.Name);
                try
                {
                    var act = (Action<MyPackage>)Delegate.CreateDelegate(typeof(Action<MyPackage>), t, method);
                    DictAction[pid] = act;
                    DictMethod[pid] = method.Name;
                }
                catch
                {
                }
            }
        }
        public static void Acs(params object[] ts)
        {
            foreach (var item in ts)
            {
                AddController(item);
            }
        }
    }
}
